export function withDefaults<T, D extends unknown>(value: T, defaultValue: D) {
    if (defaultValue !== null && !(defaultValue instanceof Array) && typeof defaultValue === "object") {
        let obj = value ?? ({} as T & D);
        Object.keys(defaultValue).forEach(key => {
            obj[key as keyof typeof obj] = withDefaults(value?.[key as keyof T], defaultValue[key as keyof D]) as any;
        });
        return obj as T & D;
    } else {
        return (value ?? defaultValue) as T & D;
    }
}